package com.zzx.util;

import com.zzx.domain.LoginUser;
import com.zzx.exception.ExceptionState;
import com.zzx.exception.SystemException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Objects;

public class SecurityContextHolderUtils {

    public static LoginUser getLoginUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        if(Objects.isNull(loginUser)) throw new SystemException(ExceptionState.NONUSER);
        return loginUser;
    }
    public static Integer getId(){
        return getLoginUser().getManager().getMgId();
    }

}
